const int mod = 998244353;
void solve()
{
  int n;
  cin >> n;

  vi a(n);
  rep(i, 0, n - 1) {
    cin >> a[i];
  }

  CartesianTree<int> ct(a);
  vl dp(n);

  auto dfs = [&](auto &&dfs, int u, int f) -> void {
    if (ct.ls[u] != -1) {
      dfs(dfs, ct.ls[u], f | 1);
    }
    if (ct.rs[u] != -1) {
      dfs(dfs, ct.rs[u], f | 2);
    }
    ll lv = (ct.ls[u] == -1 ? 1 : dp[ct.ls[u]]);
    ll rv = (ct.rs[u] == -1 ? 1 : dp[ct.rs[u]]);
    dp[u] = (dp[u] + lv * rv) % mod;
    if (f & 1) {
      dp[u] = (dp[u] + lv) % mod;
    }
    if (f & 2) {
      dp[u] = (dp[u] + rv) % mod;
    }
    if (f == 3) {
      dp[u] = (dp[u] - 1) % mod;
      if (dp[u] < 0) {
        dp[u] += mod;
      }
    }
  };
  dfs(dfs, ct.rt, 0);
  ll lv = (ct.ls[ct.rt] == -1 ? 1 : dp[ct.ls[ct.rt]]);
  ll rv = (ct.rs[ct.rt] == -1 ? 1 : dp[ct.rs[ct.rt]]);
  cout << lv * rv % mod << '\n';
}